<!--conf
<sample in_favorites="false">
              <product version="1.4" edition="std"/>
                     <modifications>
                            <modified date="070101"/>
                     </modifications>
               <sampledescription><![CDATA[Sample demonstrates the possibility to select block of data in grid and copy it to clipboard for further usage in other programs or in another place of grid.]]></sampledescription></sample>
 --> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Copy to clipboard</title>
	
</head>

<body>
<link rel='STYLESHEET' type='text/css' href='../common/style.css'>
<table cellspacing="0" cellpadding="0" class="sample_header" border="0">
	<tr valign="middle">
		<!-- COMPONENT ICON -->
		<td width="40" align="center"><img src="../common/dhtmlxgrid_icon.gif" border="0"></td>
		<!-- COMPONENT NAME -->
		<td width="150" align="left" nowrap="true">Sample: dhtmlxGrid</td>
		<!-- SAMPLE TITLE -->
		<td width="0" align="left" nowrap><b>Copy to clipboard</b></td>
		<!-- LINK TO COMPONENT PAGE -->
		<td width="0" align="right"><a href="http://www.dhtmlx.com/docs/products/dhtmlxGrid/index.shtml">dhtmlxGrid main page</a></td>
		<!-- CLOSE BUTTON -->
		<td width="50"><div class="sample_close"><a href="javascript:void(0);" onclick="self.close();"><img src="../common/sample_close.gif" width="14" height="14" border="0" alt="X"></a></div></td>
	</tr>
</table>
	
	
	To select area in grid - hold left mouse button and move mouse to spread selection.<br/>
	Press Ctrl+C to copy seleted rows into the clipboard,  Ctrl+V to replace selected rows by rows from clipboard.</br> You can paste selected rows to Excell.  
	<link rel="STYLESHEET" type="text/css" href="../../codebase/dhtmlxgrid.css">
	<link rel="STYLESHEET" type="text/css" href="../../codebase/dhtmlxgrid_skins.css">
	<script  src="../../codebase/dhtmlxcommon.js"></script>
	<script  src="../../codebase/dhtmlxgrid.js"></script>
	<script  src="../../codebase/dhtmlxgridcell.js"></script>
	<script  src="../../codebase/ext/dhtmlxgrid_selection.js"></script>
	<script  src="../../codebase/ext/dhtmlxgrid_nxml.js"></script>
	<table width="100%">
		<tr>
			<td width="500px" valign="top">
				<div id="gridbox" width="500px" height="250px" style="background-color:white;overflow:hidden"></div>
			</td>
			<td width="300px">
				<textarea style="font-size:8pt; font-family:Arial; width:400px; height:250px;" id="ser_1"></textarea>
			</td>

		</tr>
		<tr>
			<td></td>
			<td>
				<div><a href="#" onclick="showClipboard()">show clipboard</a></div>
      
			</td>
		</tr>
	</table>
<br>
<div class='sample_code'><div class="hl-main"><pre><span class="hl-code"> 
    
 </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">attachEvent</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">onKeyPress</span><span class="hl-quotes">&quot;</span><span class="hl-code">,</span><span class="hl-identifier">onKeyPressed</span><span class="hl-brackets">)</span><span class="hl-code">;
    ...
</span><span class="hl-reserved">function</span><span class="hl-code"> </span><span class="hl-identifier">onKeyPressed</span><span class="hl-brackets">(</span><span class="hl-identifier">code</span><span class="hl-code">,</span><span class="hl-identifier">ctrl</span><span class="hl-code">,</span><span class="hl-identifier">shift</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
        
    </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-identifier">code</span><span class="hl-code">==</span><span class="hl-number">67</span><span class="hl-code">&amp;&amp;</span><span class="hl-identifier">ctrl</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">copyBlockToClipboard</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
    </span><span class="hl-brackets">}</span><span class="hl-code">
        
    </span><span class="hl-reserved">if</span><span class="hl-brackets">(</span><span class="hl-identifier">code</span><span class="hl-code">==</span><span class="hl-number">86</span><span class="hl-code">&amp;&amp;</span><span class="hl-identifier">ctrl</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-identifier">mygrid</span><span class="hl-code">.</span><span class="hl-identifier">pasteBlockFromClipboard</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">
    </span><span class="hl-brackets">}</span><span class="hl-code">
        
    </span><span class="hl-reserved">return</span><span class="hl-code"> </span><span class="hl-reserved">true</span><span class="hl-code">;
</span><span class="hl-brackets">}</span></pre></div></div>

<style>

.dhtmlxGrid_selection {
	-moz-opacity: 0.5;
	filter: alpha(opacity = 50);
	background-color:#83abeb;
	opacity:0.5;
}


</style>
<script>

	mygrid = new dhtmlXGridObject('gridbox');
	mygrid.setImagePath("../../codebase/imgs/");
	mygrid.setHeader("Sales,Book Title,Author,Price,In Store,Shipping,Bestseller,Date of Publication");
	mygrid.setInitWidths("50,150,120,80,80,80,80,200")
	mygrid.setColAlign("right,left,left,right,center,left,center,center")
	mygrid.setColTypes("dyn,ed,ed,price,ch,co,ra,ro");
	mygrid.setColSorting("int,str,str,int,str,str,str,date")
	mygrid.enableAlterCss("even","uneven");
   	mygrid.attachEvent("onKeyPress",onKeyPressed);
   	mygrid.attachEvent("onBeforeSelect",function(){ return false; });
	mygrid.init();
	mygrid.setSkin("modern")
	mygrid.loadXML("grid.xml");
	mygrid.enableBlockSelection();
	
	 function onKeyPressed(code,ctrl,shift){
				if(code==67&&ctrl){
					if (!mygrid._selectionArea) return alert("You need to select a block area in grid first");
					mygrid.setCSVDelimiter("\t")
					mygrid.copyBlockToClipboard()
				}
				if(code==86&&ctrl){
					mygrid.pasteBlockFromClipboard()
				}
		return true;
    }
	function showClipboard(){
			 if (window.clipboardData)
   					document.getElementById("ser_1").value = window.clipboardData.getData("Text");		
	}
	
window.onerror=function(){
	alert("Clipboard operations not enabled in your browser.");
	window.open("http://www.febooti.com/support/website-help/website-javascript-copy-clipboard.html","_blank");
}
</script>

<!-- FOOTER -->
<table callspacing="0" cellpadding="0" border="0" class="sample_footer"><tr><td style="padding-left: 8px;">&copy; <a href="http://www.dhtmlx.com">DHTMLX LTD</a>. All rights reserved</td></tr></table>
<!-- FOOTER -->

</body>
</html>
